# Maintainer: Jelle van der Waa <jelle@archlinux.org>

pkgname=nginx-prometheus-exporter
pkgdesc='NGINX Prometheus Exporter for NGINX and NGINX Plus'
pkgver=0.8.0
pkgrel=1
arch=(x86_64)
license=('Apache')
url="https://github.com/nginxinc/nginx-prometheus-exporter"
depends=(glibc)
makedepends=(go)
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/nginxinc/nginx-prometheus-exporter/archive/v${pkgver}.tar.gz
        nginx-prometheus-exporter.service
        nginx-prometheus-exporter.conf)
sha512sums=('ee49cfc06606494812a9f5218fe16d53dc3edfa6fc67a83f177bb64fceada08215e84dd6cc4b959d741b84a9c09dc029171a204fdfc36a440113f398d933b849'
            'd29541b1afe15bfe90ac9d54f0771ade4c8cd9d4291d0a9b1e9ffb4f38f1ae3739bef79a0120ca7c79ea5b580d224b09e9ca7645c92d8c4bc991532759249bb5'
            '843d6903c8da8356cef0c53722c176f5ed12d140a2888f3f3cf5dedaf6437fdc3c0a527ba6635bd949b28a64af98221aeb5caa13edb12b05a712c6e2aadddf77')

build() {
  cd "$pkgname-$pkgver"
  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"  -X main.version=${pkgver} -X main.gitCommit=${pkgver}" \
    .
}

check() {
  cd "$pkgname-$pkgver"
  go test ./... 
}

package() {
  install -Dm644 nginx-prometheus-exporter.service "$pkgdir"/usr/lib/systemd/system/nginx-prometheus-exporter.service
  install -Dm644 nginx-prometheus-exporter.conf "${pkgdir}"/etc/conf.d/nginx-prometheus-exporter

  cd "$pkgname-$pkgver"
  install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname

}
